package main

import (
	"fmt"
	"os"
	"time"
)

func main() {
	fifoPath := "/tmp/my_pipe"

	// 打开命名管道（阻塞直到有读进程）
	file, err := os.OpenFile(fifoPath, os.O_WRONLY, os.ModeNamedPipe)
	if err != nil {
		fmt.Printf("打开失败: %v\n", err)
		return
	}
	defer file.Close()

	for i := 1; i <= 5; i++ {
		msg := fmt.Sprintf("消息%d [时间:%v]", i, time.Now().Format("15:04:05"))
		_, err := file.WriteString(msg + "\n")
		if err != nil {
			fmt.Printf("写入失败: %v\n", err)
			return
		}
		fmt.Printf("已发送: %s\n", msg)
		time.Sleep(1 * time.Second)
	}
}
